<?php

function getPushUrl($domain, $streamName, $key = null, $time = null){
    if($key && $time){
          $txTime = strtoupper(base_convert(strtotime($time),10,16));
          //txSecret = MD5( KEY + streamName + txTime )
          $txSecret = md5($key.$streamName.$txTime);
          $ext_str = "?".http_build_query(array(
                "txSecret"=> $txSecret,
                "txTime"=> $txTime
          ));
    }
    $data['push'] = "rtmp://".$domain."/live/".$streamName . (isset($ext_str) ? $ext_str : "");
    $data['play'] = "http://bofangliu.xingouyuan.com/live/".$streamName.'.flv';
    $data['stream_name'] = $streamName;
    return $data;
}


    
function main_handler($event, $context) {
    $name = random_int(100000, 999999);

    //$time = date('Y-m-d H:i:s');
    $time = date('Y-m-d H:i:s', strtotime("+1 week"));

    $data = getPushUrl("89716.livepush.myqcloud.com", $name, "dd5f5be200bfc814438632bb294112ab", $time);
   # file_put_contents('zhibodata.txt', json_encode($data));

    return json_encode($data);
}

//$name = random_int(100000, 999999);
$name = $_GET['liveid'];
    //$time = date('Y-m-d H:i:s');
$time = date('Y-m-d H:i:s', strtotime("+1 week"));

$data = getPushUrl("89716.livepush.myqcloud.com", $name, "dd5f5be200bfc814438632bb294112ab", $time);
# file_put_contents('zhibodata.txt', json_encode($data));

echo json_encode($data);

?>
